home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1996 #15 / Monster Media Number 15 (Monster Media)(July 1996).ISO / prog_d / tpop3.zip / MSGUTILS.PAS < prev    next >
Pascal/Delphi Source File  |  1996-04-07  |  2KB  |  113 lines

  1. unit Msgutils;
  2.  
  3. interface
  4.  
  5. uses Classes,SysUtils;
  6.  
  7. function TrimStr(s : string) : string;
  8. procedure TrimStringList(SL : TStrings);
  9. function GetHeaderValue(Hdr : TStrings; const ID : string) : string;
  10. function GetParameter(const p : string; s : string) : string;
  11. function AddBackSlash(const DirName : string) : string;
  12.  
  13. const
  14.   InvStr = '$$Unable to Get$$';
  15.  
  16. implementation
  17.  
  18. function TrimStr(s : string) : string;
  19. var
  20.   sLen : byte absolute s;
  21. begin
  22.   while (sLen>0) and (s[1] in [' ',^I]) do
  23.     Delete(s,1,1);
  24.   while (sLen>0) and (s[sLen] in [' ',^I]) do
  25.     Dec(sLen);
  26.   result:=s;
  27. end;
  28.  
  29. procedure TrimStringList(SL : TStrings);
  30. var
  31.   i : Integer;
  32. begin
  33.   with SL do
  34.   begin
  35.     while (Count>0) and (Strings[0]='') do
  36.       Delete(0);
  37.     while (Count>0) and (Strings[Count-1]='') do
  38.       Delete(Count-1);
  39.   end;
  40. end;
  41.  
  42. function GetHeaderValue(Hdr : TStrings; const ID : string) : string;
  43. var
  44.   Found : boolean;
  45.   i,j : Integer;
  46. begin
  47.   Found:=false; Result:='';
  48.   for i:=0 to Hdr.Count-1 do
  49.   if Pos(UpperCase(ID),UpperCase(Hdr[i]))=1 then
  50.   begin
  51.     Found:=true;
  52.     Break;
  53.   end;
  54.   if Found then
  55.   begin
  56.     Result:=Hdr[i];
  57.     j:=Pos(':',Result);
  58.     Delete(Result,1,j+1);
  59.     Result:=TrimStr(Result);
  60.     Inc(i);
  61.     while (i<=Hdr.Count-1) and (Pos(':',Hdr[i])=0) do
  62.     begin
  63.       Result:=Concat(Result,' ',TrimStr(Hdr[i]));
  64.       Inc(i);
  65.     end;
  66.   end;
  67. end;
  68.  
  69. function GetParameter(const p : string; s : string) : string;
  70. {Gets p="value" or p=value, returns 'value'}
  71. {April 07, 1996, removing trailing ;}
  72. var
  73.   i : Integer;
  74.   LastCh : Char;
  75. begin
  76.   Result:=InvStr;
  77.   i:=Pos(UpperCase(p),UpperCase(s));
  78.   if i<>0 then
  79.   begin
  80.     Result:='';
  81.     Delete(s,1,i+Length(p));
  82.     s:=TrimStr(s);
  83.     if s[1]='"' then
  84.     begin
  85.       LastCh:='"';
  86.       i:=2;
  87.     end
  88.     else
  89.     begin
  90.       LastCh:=' ';
  91.       i:=1;
  92.     end;
  93.     while (i<=Length(s)) and (s[i]<>LastCh) do
  94.     begin
  95.       Result:=Concat(Result,s[i]);
  96.       Inc(i);
  97.     end;
  98.     if Result[Length(Result)]=';' then
  99.       Delete(Result,Length(Result),1);
  100.     Result:=TrimStr(Result);
  101.   end;
  102. end;
  103.  
  104. function AddBackSlash(const DirName : string) : string;
  105. var
  106.   sLen : byte absolute DirName;
  107. begin
  108.   if (sLen>0) and (DirName[sLen]<>'\') then Result:=Concat(DirName,'\')
  109.     else Result:=DirName;
  110. end;
  111.  
  112. end.
  113.